home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / Ant Movie Catalog 3.5.0.2 / amc_install.exe / {app} / Scripts / IMP Awards.ifs < prev    next >
Text File  |  2005-03-13  |  4KB  |  149 lines

  1. (***************************************************
  2.  
  3. Ant Movie Catalog importation script
  4. www.antp.be/software/moviecatalog/
  5.  
  6. [Infos]
  7. Authors=micmic
  8. Title=IMP Awards
  9. Description=Movie importation script for IMP Awards
  10. Site=http://www.impawards.com/
  11. Language=EN
  12. Version=1.0
  13. Requires=3.5.0
  14. Comments=
  15. License=This program is free software; you can redistribute it and/or modify it under the  terms of the GNU General Public License as published by the Free Software Foundation;  either version 2 of the License, or (at your option) any later version. |
  16. GetInfo=1
  17.  
  18. [Options]
  19.  
  20. ***************************************************)
  21.  
  22. program micmic;
  23. var
  24.   MovieName: string;
  25. const
  26.   BaseURL = 'http://www.impawards.com/cgi-bin/htsearch?method=or&words=';
  27.  
  28. function FindLine(Pattern: string; List: TStringList; StartAt: Integer): Integer;
  29. var
  30.   i: Integer;
  31. begin
  32.   result := -1;
  33.   if StartAt < 0 then
  34.     StartAt := 0;
  35.   for i := StartAt to List.Count-1 do
  36.     if Pos(Pattern, List.GetString(i)) <> 0 then
  37.     begin
  38.       result := i;
  39.       Break;
  40.     end;
  41. end;
  42.  
  43. procedure AnalyzePage(Address: string);
  44. var
  45.   Page: TStringList;
  46.   LineNr: Integer;
  47.   PosIni, PosFin: Integer;
  48.   Line, SubLine: string;
  49.   Title, DirURL: string;
  50.   txtTemp: string;
  51. begin
  52.   Page := TStringList.Create;
  53.   Page.Text := GetPage(Address);
  54.   if Pos('IMP could not find any matches for', Page.Text) > 0 then
  55.   begin
  56.     ShowMessage('No matches for the title search.');
  57.   end else
  58.   begin
  59.     PickTreeClear;
  60.     PickTreeAdd('Resuts for the search of "' + MovieName + '":', '');
  61.  
  62.     // buscamos los resultados
  63.     LineNr := 0;
  64.  
  65.     while LineNr < Page.Count do
  66.     begin
  67.       SubLine := Page.GetString(LineNr);
  68.       txtTemp := '<dl><dt><strong><a href="';
  69.       PosIni := pos(txtTemp, SubLine);
  70.       if PosIni > 0 then
  71.       begin
  72.         //ShowMessage(IntToStr(PosIni));
  73.         SubLine := Copy(SubLine, PosIni + Length(txtTemp), Length(SubLine));
  74.        
  75.         txtTemp := '">';
  76.         PosFin := pos(txtTemp, SubLine);
  77.         DirURL := Copy(SubLine, 1, PosFin - 1);
  78.        
  79.         SubLine := Copy(SubLine, PosFin + Length(txtTemp), Length(SubLine));
  80.         txtTemp := '</a>';
  81.         PosFin := pos(txtTemp, SubLine);
  82.         Title := Copy(SubLine, 1, PosFin - 1);
  83.  
  84.         //ShowMessage(Title + '-->' + DirURL);
  85.         PickTreeAdd(Title, DirURL);
  86.       end;
  87.       LineNr := LineNr + 1;
  88.     end;
  89.  
  90.     Page.Free;
  91.     if PickTreeExec(Address) then
  92.       AnalyzeMoviePage(Address);
  93.   end;
  94. end;
  95.  
  96.  
  97. procedure AnalyzeMoviePage(Address: string);
  98. var
  99.   Page: TStringList;
  100.   PosIni, PosFin: Integer;
  101.   dirBase: string;
  102.   txtTemp: string;
  103.   ImgTMP: string;
  104. begin
  105.   Page := TStringList.Create;
  106.   Page.Text := StringReplace(GetPage(Address), '<br>', #13#10);
  107.  
  108.   //obtenemos directorio base
  109.   PosFin := 0;
  110.   dirBase := Address;
  111.   PosIni := pos('/', dirBase);
  112.   while PosIni > 0 do
  113.   begin
  114.     PosFin := PosFin + PosIni;
  115.     dirBase := Copy(dirBase, PosIni + 1, Length(DirBase));
  116.     PosIni := pos('/', dirBase);
  117.   end;
  118.   dirBase := Copy(Address, 1, PosFin);
  119.  
  120.   //buscamos la imagen
  121.   txtTemp := '<img SRC="posters/';
  122.   PosIni := pos(txtTemp, Page.Text);
  123.   if PosIni > 0 then
  124.   begin
  125.     txtTemp := Copy(Page.Text, PosIni + Length(txtTemp), 100);
  126.     PosFin := pos('"', txtTemp);
  127.     ImgTMP := Copy(txtTemp, 1, PosFin - 1);
  128.  
  129.     GetPicture(dirBase + 'posters/' + ImgTMP);
  130.   end;
  131.  
  132.   Page.Free;
  133.   //DisplayResults;
  134. end;
  135.  
  136. // bmicmic: Bucle Principal
  137. begin
  138.   if CheckVersion(3,5,0) then
  139.   begin
  140.     MovieName := GetField(fieldOriginalTitle);
  141.     if MovieName = '' then
  142.       MovieName := GetField(fieldTranslatedTitle);
  143.     Input('Import of IMP Awards', 'Enter the title of the movie:', MovieName);
  144.     AnalyzePage(BaseURL + UrlEncode(MovieName));
  145.  
  146.   end else
  147.        ShowMessage('This scripts requires a new version of Ant Movie Catalog (at least the version 3.5.0)');
  148. end.
  149.